// 定义 Store
import {
	defineStore
} from 'pinia'
import {
	ref,
	computed
} from "vue"
const useCartStore = defineStore('cart', () => {
	// state
	const price = ref(10)
	// getter
	const doublePrice = computed(() => {
		return price.value * 2
	})
	// action
	const priceInc = () => {
		price.value++
	}

	return {
		price,
		doublePrice,
		priceInc
	}
}, {
	// 兼容多端
	persist: {
		storage: {
			getItem(key) {
				return uni.getStorageSync(key)
			},
			setItem(key, value) {
				uni.setStorageSync(key, value)
			},
		},
	}
})

export default useCartStore